import java.lang.Thread;
/*
 * Main.fx
 *
 * Created on 07/10/2011, 14:36:17
 */

/**
 * @author Pedro
 */
public class Main {

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:main
    public-read def button: javafx.scene.control.Button = javafx.scene.control.Button {
        layoutX: 89.0
        layoutY: 31.0
        text: "Button"
        action: buttonAction
    }
    
    public-read def textBox: javafx.scene.control.TextBox = javafx.scene.control.TextBox {
        layoutX: 143.0
        layoutY: 6.0
    }
    
    public-read def txtLoginValueLabel: javafx.scene.control.Label = javafx.scene.control.Label {
    }
    
    public-read def txtSenhaValueLabel: javafx.scene.control.Label = javafx.scene.control.Label {
    }
    
    public-read def formContainerVBox: javafx.scene.layout.VBox = javafx.scene.layout.VBox {
        content: [ txtLoginValueLabel, txtSenhaValueLabel, ]
        spacing: 6.0
    }
    
    public-read def scene: javafx.scene.Scene = javafx.scene.Scene {
        content: getDesignRootNodes ()
    }
    
    public-read def currentState: org.netbeans.javafx.design.DesignState = org.netbeans.javafx.design.DesignState {
    }
    
    public function getDesignRootNodes (): javafx.scene.Node[] {
        [ button, textBox, formContainerVBox, ]
    }
    
    public function getDesignScene (): javafx.scene.Scene {
        scene
    }
    // </editor-fold>//GEN-END:main

    function buttonAction(): Void {

        var rmi: RmiClient;
        rmi = RmiClient.getInstance();
        var retorno = rmi.isValidAuthentication("pedrohrs08", "a@W#E$R%095895");
        textBox.text = retorno.toString();

        var clientBt: ClientBt;
        clientBt = new ClientBt(rmi, "pedrohrs08");
        var thread: Thread;
        thread = new Thread(clientBt);
        thread.start();
        var networkId: Integer;
        while (clientBt.completedServicesSearch) { };

        var ServicosAchador: Integer;
        ServicosAchador = clientBt.servicosAchados;
        networkId = clientBt.networkId;
        if (ServicosAchador <= 0) {
            networkId = rmi.getNewNetworkId();
            rmi.requestSongs("pedrohrs08", networkId);

        }

        var tServer: Thread;
        tServer = new Thread(new ServerBt("pedrohrs08", networkId));
        tServer.start();

    }

}

function run (): Void {
    var design = Main {};

    javafx.stage.Stage {
        title: "Main"
        scene: design.getDesignScene ()
    }
}
